package org.gq.action.contextconfig;

import java.beans.Introspector;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.util.ClassUtils;

/**
 * class name = interface name + "Impl"
 * so spring bean name = class name - "Impl"
 * @author GQ
 */
public class SpringNameGenerator extends AnnotationBeanNameGenerator {
	protected String buildDefaultBeanName(BeanDefinition definition) {
		String shortClassName = ClassUtils.getShortName(definition.getBeanClassName());
		String beanName = Introspector.decapitalize(shortClassName);

		String suffix = "Impl";
		if (beanName.endsWith(suffix))
			beanName = beanName.substring(0, beanName.length() - suffix.length());

		return beanName;
	}
}
